/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : ImageHtml.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Dec 13, 2008       Raghu Sarraff			       Created
 */
package net.lwf.handler.util;

import java.util.List;

import net.lwf.handler.constant.IHandlerConstant;
import net.lwf.number.util.RandomNumberGenerator;

import lwf.factory.WordImageFactory;
import lwf.handler.entities.WordImage;

/**
 * Type the class description here
 *  
 */
public class ImageHtml {
	
//	public static String getWordImage(String word) {
////		Map mapImages = PropertyReader.getInstance().getWordImages();
////		String image = "";
////		if(mapImages.containsKey(word)) {
////			List lstImages = (ArrayList) mapImages.get(word);
////			int imageIndex = 0;
////			if(lstImages.size() > 1) {
////				imageIndex = RandomNumberGenerator.generate(1, lstImages.size()) - 1;
////			}
////			image = (String) lstImages.get(imageIndex);
////		}
//		String image = null;
//		WordImage wi = WordImageFactory.getInstance().getImageByWord(word);
//		if(wi != null) {
//			image = wi.getImagePath();
//		}
//		
//		System.out.println("=======> Image: " + image);
//		if(image != null && image.trim().length() != 0) {
//			return getImageHtml(image);
//		}
//		return "";
//	}
	
	/**
	 * Gets the image html for the given word. 
	 * A particular word may have one or more images. If it has more than
	 * one image, the image html is processed based on the index value generated
	 * from the random number generated between the range 0 and the size of the available 
	 * images have for the given word.
	 * 
	 * @param word   Word name/image name
	 * 
	 * @return
	 */
	public static String getWordImage(String word) {
		String image = null;
		WordImage wi = WordImageFactory.getInstance().getImageByWord(word);
		if(wi != null) {
			List images = wi.getWordImages();
			if(images != null && images.size() > 1) {
				int index = RandomNumberGenerator.generate(1, images.size());
				wi = (WordImage) images.get(index - 1);
			}
			image = wi.getImagePath();
		}
		
		if(image != null && image.trim().length() != 0) {
			return getImageHtml(image);
		}
		return "";
	}
	
	/**
	 * Gets the image html for the given word. 
	 * A particular word may have one or more images. If it has more than
	 * one image, the image html is processed based on the index provided.
	 * 
	 * @param word   Word name/image name
	 * @param index  
	 * 
	 * @return
	 */
	public static String getWordImage(String word, int index) {
		String image = null;
		WordImage wi = WordImageFactory.getInstance().getImageByWord(word);
		if(wi != null) {
			List images = wi.getWordImages();
			if(images != null && images.size() > 1) {
				wi = (WordImage) images.get(index - 1);
			}
			image = wi.getImagePath();
		}
		
		if(image != null && image.trim().length() != 0) {
			return getImageHtml(image);
		}
		return "";
	}
	
	
	public static String getBulletImage() {
		return getBulletImage(RandomNumberGenerator.generate(1, 2));
	}
	
	public static String getBulletImage(int bullettype) {
		int bullet = 0;
		if(bullettype == 1) {
			bullet = RandomNumberGenerator.generate(1, 5); //currently 5 type 1 bullets are available
		}
		else {
			bullet = RandomNumberGenerator.generate(1, 4); //currently 4 type 2 bullets are available
		}
		
		String image = "image/bullets/bullet" + String.valueOf(bullettype) + "_" + String.valueOf(bullet) + ".gif";

		return getImageHtml(image);
	}
	
	public static String getDotImage() {
		int dot = RandomNumberGenerator.generate(1, 19);
		String image = "image/dots/dot" + "_" + String.valueOf(dot) + ".gif";
		return getImageHtml(image);
	}
	
	/**
	 * @param type
	 * @param onclick
	 * @return
	 */
	public static String getButton(String type, String onclick) {
		String image = "image/button/" + type + "up.png";
		return getImageHtml(image, onclick);
	}
	
	public static String getStartButton(String onclick) {
		String image = "image/button/" + IHandlerConstant.START + "up.png";
		return getImageHtml(image, onclick);
	}
	
	public static String getEmptyImage() {
		return getImageHtml("/" + IHandlerConstant.CONTEXT_PATH + "/image/empty.gif");
	}
	
	/**
	 * Gets the image html
	 * 
	 * @param image fully qualified image location
	 * 
	 * @return
	 */
	public static String getImageHtml(String image, String onclick) {
		if(onclick != null) {
			//return "<image src=\"" + image + "\"" + " onclick=\"" + onclick + "\"" + " border=\"" + 0 + "\" >";
			return "<img src=\"" + image + "\"" + " onclick=\"" + onclick + "\"" + " border=\"" + 0 + "\" >";
		}
		//return "<image src=\"" + image + "\"" + " border =\"" + 0 + "\" >";
		return "<img src=\"" + image + "\"" + " border =\"" + 0 + "\" >";
	}
	
	/**
	 * Gets the image html
	 * 
	 * @param image fully qualified image location
	 * 
	 * @return
	 */
	public static String getImageHtml(String image) {
		//return "<image src=\"" + image + "\">";
		return "<img src=\"" + image + "\">";
	}
	
}

